package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsProtectWork;
import com.ruoyi.system.domain.news.query.NewsProtectWorkQuery;
import com.ruoyi.system.domain.news.vo.NewsProtectWorkVo;
import com.ruoyi.system.service.news.NewsProtectWorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsProtectWork")
@Api(value = "newsProtectWorkApiController", tags  = "等级保护工作Api")
public class NewsProtectWorkApiController extends BaseController {

	@Resource
	private NewsProtectWorkService newsProtectWorkService;

	@ApiOperation(value = "获取单个等级保护工作信息", notes = "获取单个等级保护工作信息")
	@GetMapping("/getById")
	public R<NewsProtectWorkVo> getById(@RequestParam(value = "id") Long id) {
		NewsProtectWorkQuery NewsProtectWorkQuery = new NewsProtectWorkQuery();
		NewsProtectWorkQuery.setId(id);
		List<NewsProtectWorkVo> NewsProtectWorkList = newsProtectWorkService.getNewsProtectWorkList(NewsProtectWorkQuery);
		if (NewsProtectWorkList!=null&&NewsProtectWorkList.size()>0) {
			return R.ok(NewsProtectWorkList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取等级保护工作信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsProtectWorkVo>> list(@RequestBody NewsProtectWorkQuery NewsProtectWorkQuery) {
        NewsProtectWorkQuery.setIsEnable("1");
		List<NewsProtectWorkVo> NewsProtectWorkList = newsProtectWorkService.getNewsProtectWorkList(NewsProtectWorkQuery);
		return R.ok(new PageInfo<>(NewsProtectWorkList));
	}
}
